<template>
  <el-dialog
    width="90%"
    title=""
    custom-class="techDialog"
    :visible.sync="priceVisible"
    :modal="true"
    :close-on-click-modal="false"
    append-to-body
  >
    <div slot="title" class="clearfix flex flex-row align-center">
      <div class="line" />
      <span class="font16 ml10 fw600">收费编码查询</span>
    </div>
    <el-form ref="queryPriceForm" :model="queryParams" :inline="true">
      <el-form-item label="项目名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入项目名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方法">
        <el-select
          v-model="queryParams.payMethod"
          filterable
          clearable
          size="small"
          placeholder="请选择支付方法"
          style="width: 190px"
        >
          <el-option
            v-for="item in PayMethodOptions"
            :key="item.id"
            :label="item.label"
            :value="item.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="费用类别">
        <el-select
          v-model="queryParams.priceType"
          filterable
          clearable
          size="small"
          placeholder="请选择支付方法"
          style="width: 150px"
        >
          <el-option
            v-for="item in PriceTypeOptions"
            :key="item.id"
            :label="item.label"
            :value="item.label"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="small"
          @click="handleLimitQuery"
        >搜索</el-button>
        <el-button
          icon="el-icon-refresh"
          size="small"
          @click="resetLimitQuery"
        >重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      ref="techTable"
      v-loading="loading"
      border
      tooltip-effect="dark"
      :data="priceList"
      :header-cell-class-name="cellClass"
      @select="selectTech"
    >
      <el-table-column
        type="selection"
        width="80"
        align="center"
      />
      <el-table-column
        label="医保编码"
        prop="medicalCode"
        align="center"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="项目编码"
        prop="projectNo"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="支付方法"
        prop="payMethod"
        align="center"
        width="100"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="项目名称"
        prop="name"
        align="center"
        :show-overflow-tooltip="true"
      />
      <!-- <el-table-column
        label="项目内涵"
        prop="description"
        align="center"
        :show-overflow-tooltip="true"
      /> -->

      <el-table-column
        label="计价单位"
        prop="unit"
        align="center"
        width="100"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="收费标准"
        prop="charges"
        align="center"
        width="100"
        :show-overflow-tooltip="true"
      />
      <!-- <el-table-column
        label="限定内容"
        prop="restrictedContent"
        align="center"
        width="100"
        :show-overflow-tooltip="true"
      /> -->
      <el-table-column
        label="费用类别"
        prop="priceType"
        align="center"
        width="100"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="国家医保编码"
        prop="gjMedicalCode"
        align="center"
        width="170"
        :show-overflow-tooltip="true"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      class="tech"
      :page.sync="queryParams.pageIndex"
      :limit.sync="queryParams.pageSize"
      @pagination="getPriceNoListHandel"
    />
    <div slot="footer" class="flex flex-row justify-content-center">
      <div class="btn-list">
        <el-button size="small" @click="close">取消</el-button>
        <el-button
          size="small"
          type="primary"
          :disabled="selectPriceData.length == 0"
          @click="enterPrice"
        >确认选择</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getPriceNoList } from '@/api/xjs/tech'
export default {
  name: 'PriceDialog',
  data() {
    return {
      priceList: [],
      selectPriceData: [],
      loading: false,
      priceVisible: false,
      downloadVisible: false,
      downloadFirstVisible: false,
      total: 0,
      queryParams: {
        pageIndex: 1,
        pageSize: 5,
        name: undefined,
        payMethod: undefined,
        priceType: undefined
      },
      PayMethodOptions: [
        {
          id: 1,
          label: '不支付'
        },
        {
          id: 2,
          label: '部分支付'
        },
        {
          id: 3,
          label: '全额支付'
        },
        {
          id: 4,
          label: '限定部分支付'
        },
        {
          id: 5,
          label: '限定全额支付'
        },
        {
          id: 6,
          label: '约定、部分支付'
        },
        {
          id: 7,
          label: '约定、全额支付'
        },
        {
          id: 8,
          label: '约定、限定全额支付'
        }
      ],
      PriceTypeOptions: [
        {
          id: 1,
          label: '护理费'
        },
        {
          id: 2,
          label: '化验费'
        },
        {
          id: 3,
          label: '检查费'
        },
        {
          id: 4,
          label: '摄片费'
        },
        {
          id: 5,
          label: '手术材料费'
        },
        {
          id: 6,
          label: '输血费'
        },
        {
          id: 7,
          label: '输氧费'
        },
        {
          id: 8,
          label: '透视费'
        },
        {
          id: 9,
          label: '诊疗费'
        },
        {
          id: 10,
          label: '治疗费'
        },
        {
          id: 11,
          label: '住院床位费'
        },
        {
          id: 12,
          label: '其他'
        }
      ]
    }
  },
  methods: {
    close() {
      this.priceVisible = false
    },
    open() {
      this.priceVisible = true
      this.getPriceNoListHandel()
    },

    // 隐藏表头中的全选框
    cellClass(row) {
      if (row.columnIndex === 0) {
        return 'disabledCheck'
      }
    },
    selectTech(selection, row) {
      // 清除 所有勾选项
      this.selectPriceData = []
      this.$refs.techTable.clearSelection()
      // 当表格数据都没有被勾选的时候 就返回
      // 主要用于将当前勾选的表格状态清除
      if (selection.length == 0) return
      this.$refs.techTable.toggleRowSelection(row, true)
      this.selectPriceData.push(row)
      console.log(this.selectPriceData)
    },

    enterPrice() {
      this.$emit('enterPrice', this.selectPriceData)
      this.priceVisible = false
    },

    handleLimitQuery() {
      this.queryParams.pageIndex = 1
      this.getPriceNoListHandel()
    },
    /** 重置按钮操作 */
    resetLimitQuery() {
      this.resetForm('queryPriceForm')
      this.queryParams = {
        pageIndex: 1,
        pageSize: 5,
        name: undefined,
        payMethod: undefined,
        priceType: undefined
      }
      this.handleLimitQuery()
    },
    handleSelectionChange(selection) {},
    getPriceNoListHandel() {
      this.selectPriceData = []
      this.loading = true
      getPriceNoList(this.queryParams).then(response => {
        this.priceList = response.data.list
        this.total = response.data.count
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-pager li {
  padding: 0 4px;
  background: #fff;
  vertical-align: top;
  display: inline-block;
  font-size: 13px;
  min-width: 35.5px;
  height: 28px;
  line-height: 28px;
  cursor: pointer;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-align: center;
  margin: 0;
}
</style>
